<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改页面</title>
</head>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="/js/jquery-form.js"></script>

<script>
    function upload(){
        var form = {
            type:'post',
            url:'/upload.do',
            dataType:'json',
            success:function(data){
                //回显图片
                $("#img").prop("src",data.url);
                //隐藏域的url
                $("#url").val(data.url);
            },
            error:function(){
                alert("上传出错！")
            }
        }
        //提交
        $("#form1").ajaxSubmit(form);
    }
</script>


<body>
<form action="/update.do" method="post" id="form1" enctype="multipart/form-data">
    <%--隐藏域id--%>
        <input type="hidden" value="${product.id}" name="id">
    <table class="table table-stripped table-bordered table-hover table-condensed" style="width: 500px;text-align: center;">
        <tr>
            <td>手机名称：</td>
            <td><input type="text" name="name" value="${product.name}" class="form-control"></td>
        </tr>
        <tr>
            <td>手机价格：</td>
            <td><input type="text" name="price" value="${product.price}"></td>
        </tr>
        <tr>
            <td>出厂日期：</td>
            <td><input type="date" name="date" value="<fmt:formatDate value="${product.date}" pattern="yyyy-MM-dd"/>"></td>

        </tr>
        <tr>
            <td>是否热卖：</td>
            <td>
                <input type="radio" name="isHot" value="1"
                    <c:if test="${product.isHot==1}">checked</c:if>
                >是
                <input type="radio" name="isHot" value="0"
                       <c:if test="${product.isHot==0}">checked</c:if>
                >否
            </td>
        </tr>
        <tr>
            <td>商品描述：</td>
            <td>
                <textarea cols="30" rows="10" name="description" class="form-group">${product.description}
                </textarea>
            </td>
        </tr>
        <tr>
            <td>品牌：</td>
            <td>
                <select name="typeid" class="form-control">
                       <c:forEach items="${types}" var="type">
                           <option value="${type.tid}"
                                   <c:if test="${type.tid==product.typeid}">selected</c:if>
                           >${type.tname}</option>
                       </c:forEach>
                </select>
            </td>
        </tr>
        <tr>
            <td>上传图片</td>
            <td>
                <img src="${product.url}" alt="预览图片" id="img" width="100px" height="100px">
                <input type="file" name="myfile" onchange="upload()">
                <%--加入url隐藏域--%>
                <input type="hidden" name="url" id="url" value="${product.url}">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="修改">
                <input type="reset" value="重置">
                <input type="button" value="返回" onclick="window.history.go(-1)">
            </td>
        </tr>
    </table>
</form>

</body>
</html>
